package com.linux.huhx.thread3.join_1;

/**
 * @Author: huhx
 * @Date: 2017-10-30 上午 11:11
 */
public class MyThreadTest2 {
    public static void main(String[] args) throws InterruptedException {
        ThreadB threadB = new ThreadB();
        threadB.start();
        Thread.sleep(500);

        ThreadC threadC = new ThreadC(threadB);
        threadC.start();
    }
}

class ThreadA extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            String string = new String();
            Math.random();
        }
    }
}

class ThreadB extends Thread {
    @Override
    public void run() {
        try {
            ThreadA threadA = new ThreadA();
            threadA.start();
            threadA.join(2000);
            System.out.println("thread B end run execute");
        } catch (InterruptedException e) {
            System.out.println("thread B catch execute");
            e.printStackTrace();
        }
    }
}

class ThreadC extends Thread {
    private ThreadB threadB;

    public ThreadC(ThreadB threadB) {
        super();
        this.threadB = threadB;
    }

    @Override
    public void run() {
        threadB.interrupt();
    }
}
